package org.nimi317.web_gis.dao;


import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.nimi317.web_gis.entity.AreaQuality;
import org.nimi317.web_gis.view.RenderView;

import java.time.LocalDateTime;
import java.util.List;

/**
 * <p>
 * 每个小时的区域质量 Mapper 接口
 * </p>
 *
 * @author nimi317
 * @since 2024-01-25
 */
public interface AreaQualityMapper extends BaseMapper<AreaQuality> {

    @Select("select avg(aqi) as aqi,avg(co) as co,avg(no2) as no2,avg(o3) as o3,avg(pm10) as pm10,avg(pm25) as pm25,avg(so2) as so2,create_time as time from area_quality where city_code in ${code} and create_time >= #{time} group by create_time")
    List<RenderView> selectProvinceData(@Param("code") String code, @Param("time") LocalDateTime time);

    @Select("select avg(aqi) as aqi,avg(co) as co,avg(no2) as no2,avg(o3) as o3,avg(pm10) as pm10,avg(pm25) as pm25,avg(so2) as so2,create_time as time from area_quality where city_code in ${code} and create_time >= #{start} and create_time <= #{end} group by create_time")
    IPage<RenderView> selectProvinceHistoryData(IPage<RenderView> page, @Param("code") String code, @Param("start") LocalDateTime start, @Param("end") LocalDateTime end);

    @Select("select avg(aqi) as aqi,avg(co) as co,avg(no2) as no2,avg(o3) as o3,avg(pm10) as pm10,avg(pm25) as pm25,avg(so2) as so2,create_time as time from area_quality where city_code in ${code} and create_time >= #{start} and create_time <= #{end} group by create_time")
    List<RenderView> selectProvinceHistoryData(@Param("code") String code, @Param("start") LocalDateTime start, @Param("end") LocalDateTime end);

    @Select("select avg(aqi) as aqi,avg(co) as co,avg(no2) as no2,avg(o3) as o3,avg(pm10) as pm10,avg(pm25) as pm25,avg(so2) as so2,create_time as time from area_quality where city_code in ${code} and create_time <= #{time} group by create_time  order by create_time desc limit 24")
    List<RenderView> selectData(@Param("code") String code, @Param("time") LocalDateTime time);
}
